import tkinter

import numpy as np
from PIL import ImageTk
from PIL import Image
from wordcloud import WordCloud
import jieba  # jieba分词

from ttkbootstrap import Style


def wcd(event):
    global cut_text
    for i in range(1, 100):
        line = f.readline()  # 调用文件的 readline()方法
        cut_text = cut_text + " ".join(jieba.cut(line))
    wordcloud = WordCloud(
            # 设置字体，不然会出现口字乱码，文字的路径是电脑的字体一般路径，可以换成别的
            font_path="C:/Windows/Fonts/simfang.ttf",
            # 设置了背景，宽高
            background_color="white", width=800, height=600,
            stopwords=excludes).generate(cut_text)
    line = f.readline()
    wordcloud.to_file("./result.png")
    img = Image.open("result.png")
    imgTK = ImageTk.PhotoImage(image=img)
    canvas.create_image(400, 300, image=imgTK)


mask = np.array(Image.open(r"C:\Users\zizifreya\Desktop\testing_img\R-C.jfif"))
global f
global cut_text
global imgTK
global excludes
excludes = ['如何', "的", '问题', "报错", "了", "报错", "中",
            "吗", "在", '和', '被', '所', '这', "这个", '那',
            '有', '会', '为什么', '必须', '用', '不', '后',
            '_', '内测', '文档', '为', '时']

f = open('panddle_issus.txt', 'r', encoding='UTF-8')  # 返回一个文件对象
cut_text = " "
style = Style(theme="lumen")  # 使用的主题名称
root = style.master
root.title("IssusCloud")
canvas = tkinter.Canvas(root, width=700, height=500, bg="white")
canvas.place(x=0, y=0, width=800, height=600)
root.geometry("800x600")
root.bind("<Button-1>", wcd)  # 鼠标事件

root.mainloop()

